<?php
	//includes
	require_once 'includes.php';

	//delete all
//	DB::ExecuteSQL("
//		DELETE FROM t_product_urls;
//	");
	
//	http://market.yandex.ru/guru.xml?hid=&CMD=-RR=9,0,0,0-VIS=211E2-CAT_ID=160043-EXC=1-PG=100&greed_mode=false&ncrnd=5173
	
	//categories
	$categories = array
	(
		'mphone' => array
		(
			'id' => '160043',
			'url' => 'http://market.yandex.ru/guru.xml?CMD=-RR=9,0,0,0-VIS=*sort*-CAT_ID=160043-BPOS=*page*-EXC=1-PG=10&hid=91491'
		),
		'lense' => array
		(
			'id' => '966791',
			'url' => 'http://market.yandex.ru/guru.xml?CMD=-RR=9,0,0,0-VIS=*sort*-CAT_ID=966791-BPOS=*page*-EXC=1-PG=10&hid=90613'
		),
		'tv' => array
		(
			'id' => '108206',
			'url' => 'http://market.yandex.ru/guru.xml?CMD=-RR=9,0,0,0-VIS=*sort*-CAT_ID=108206-BPOS=*page*-EXC=1-PG=10&hid=90639'
		),
		'digital_camera' => array
		(
			'id' => '100514',
			'url' => 'http://market.yandex.ru/guru.xml?CMD=-RR=9,0,0,0-VIS=*sort*-CAT_ID=100514-BPOS=*page*-EXC=1-PG=10&hid=91148'
		),
		'flash' => array
		(
			'id' => '975897',
			'url' => 'http://market.yandex.ru/guru.xml?CMD=-RR=0,0,0,0-VIS=*sort*-CAT_ID=975897-BPOS=*page*-EXC=1-PG=10&hid=90617'
		),
	);
	
	//sort
	$sorts = array
	(
		'recent' => array
		(
			'id' => '19E2',
		),
		'popular' => array
		(
			'id' => '211E2',
		),
	);	
	
	$startTime = microtime() + time();
	
	//YandexMarket (product source)
	$yandexMarket = new YandexMarket(); 

	$currentCategory = $_GET['cat'];
	$currentSort = $_GET['sort'];
	
	//gets all URLs
	$products = $yandexMarket->GetUrls($_GET['page_from'], $_GET['page_to'], $categories[$currentCategory]['url'], $sorts[$currentSort]['id']);
	
	//saves product URLs
	$result = $yandexMarket->SaveUrls($products, $currentCategory, 'yandex', $currentSort);
	
	$endTime = microtime() + time();
	
	//totals
	$resultTime = $endTime - $startTime;
	echo "Total time: $resultTime; Success: {$result['success']}; Fail: {$result['fail']}; ";
?>